#pragma once

#include <mutex>
#include <thread>
#include <memory>
#include <functional>
#include <vector>
#include <condition_variable>
#include "zrpc/net/callback.h"

namespace zrpc {
class EventLoop;

class Thread {
 public:
  typedef std::function<void(EventLoop *)> ThreadInitCallback;

  Thread(const ThreadInitCallback &cb = ThreadInitCallback());

  ~Thread();

  EventLoop *StartLoop();
  void StopLoop();

 private:
  Thread(const Thread &);

  void operator=(const Thread &);

  void ThreadFunc();

  EventLoop *loop_;
  bool exiting_;
  mutable std::mutex mutex_;
  std::unique_ptr<std::thread> bg_thread_;
  std::condition_variable condition_;
  ThreadInitCallback callback_;
};
}  // namespace zrpc